//
//  HMComposeButton.swift
//  iOSWeibo12
//
//  Created by Admin on 16/9/21.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

/// 按钮对应的模型
class HMComposeButtonItem: NSObject {
    /// 图片
    var icon: String?
    
    /// 文字
    var title: String?
    
    // 控制器名称
    var vcName: String?
    
    // 是否是更多按钮
    var isMore = false
    
    init(dict: [String: Any]) {
        super.init()
        
        setValuesForKeys(dict)
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {}
}

// 自定义按钮
class HMComposeButton: UIControl {

    @IBOutlet weak var imageView: UIImageView!
    
    @IBOutlet weak var titleLabel: UILabel!

    var item: HMComposeButtonItem?
    
    /// 使用图像名称／标题创建按钮，按钮布局从 XIB 加载
    class func composeTypeButton(item: HMComposeButtonItem) -> HMComposeButton {
        let nib = UINib(nibName: "HMComposeButton", bundle: nil)
        let button = nib.instantiate(withOwner: nil, options: nil)[0] as! HMComposeButton
        
        button.item = item
        
        button.imageView.image = UIImage(named: item.icon!)
        button.titleLabel.text = item.title
        
        return button
    }
}
